// $Id: PluginSettings.cs 65 2008-05-06 20:58:14Z nvivo $

using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.XPath;

namespace DBLGen
{
    /// <summary>
    /// Base class for all plugin settings.
    /// </summary>
    public abstract class PluginSettings
    {
        #region Settings Manager

        public void SaveTo(SettingsManager sm)
        {
            SaveTo(sm, null);
        }

        public void SaveTo(SettingsManager sm, string key)
        {
            if (sm == null)
                throw new ArgumentNullException("sm", "SettingsManager cannot be null.");

            NameValueCollection col = SaveSettings();

            if (col != null && col.Count > 0)
                sm.Save(this.GetType(), key, col);
        }

        public bool LoadFrom(SettingsManager sm)
        {
            return LoadFrom(sm, null);
        }

        public bool LoadFrom(SettingsManager sm, string key)
        {
            if (sm == null)
                throw new ArgumentNullException("sm", "SettingsManager cannot be null.");

            NameValueCollection col = sm.Load(this.GetType(), key);

            if (col != null)
            {
                LoadSettings(col);
                return true;
            }
            else
                return false;
        }

        #endregion

        protected abstract NameValueCollection SaveSettings();
        protected abstract void LoadSettings(NameValueCollection settings);
        public abstract PluginSettings Clone();
    }
}
